<template>

  <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
    <el-card class="box-card">

      <div class="text item">
        <el-form-item label="订单号">
          <el-input v-model="tableData.orderNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="申请时间" >
          <el-input v-model="tableData.addTime" disabled></el-input>
        </el-form-item>

        <el-form-item label="订单状态" >
          <el-input v-model="tableData.orderStatusString" disabled></el-input>
        </el-form-item>
        <el-form-item label="汽车总数量" >
          <el-input v-model="tableData.carSumNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="融资经销商" >
          <el-input v-model="tableData.dealerName" disabled></el-input>
        </el-form-item>
        <el-form-item label="融资总金额(元)" >
          <el-input v-model="tableData.mortgageSumMoney" disabled></el-input>
        </el-form-item>

        <el-form-item label="初始融资期限" >
          <el-input v-model="tableData.description" disabled></el-input>
        </el-form-item>

        <el-form-item label="初始融资利率" >
          <el-input v-model="tableData.mortgageInterestRate" disabled></el-input>
        </el-form-item>

        <el-form-item label="业务员">
          <el-input v-model="tableData.businessSysUserName" disabled></el-input>
        </el-form-item>

        <el-form-item label="收款账户名" >
          <el-input v-model="tableData.accountName" disabled></el-input>
        </el-form-item>
        <el-form-item label="收款账号" >
          <el-input v-model="tableData.accountNumber" disabled></el-input>
        </el-form-item>
        <el-form-item label="开户行" >
          <el-input v-model="tableData.openningBank" disabled></el-input>
        </el-form-item>

        <el-form-item label="资源审核意见">
          <el-input v-model="tableData.resourceAuditOpinion" disabled></el-input>
        </el-form-item>

        <el-form-item label="物管验车意见" >
          <el-input v-model="tableData.propertyInspectionOpinion" disabled></el-input>
        </el-form-item>
        <el-form-item label="风控审核意见">
          <el-input v-model="tableData.riskAuditOpinion" disabled></el-input>
        </el-form-item>

      </div>
    </el-card>

    <el-card class="box-card">
      <span>审核信息</span>
      <br>
      <br>
      
      <el-table ref="multipleTable" :data="tableData.contractTemplateInfo" tooltip-effect="dark" style="width: 100%" table border @select='getTableId' @select-all='getTableId'>
        <el-table-column type="selection"   :selectable="dialogSendData.isAdd? is_select:null"  label='全选' width="55">
        </el-table-column>
        <el-table-column label="合同名称" width="120">
          <template scope="scope">{{ scope.row.name }}</template>
        </el-table-column>
        <el-table-column prop="name" label="合同别名" width="120">
          <template scope="scope">{{ scope.row.outName }}</template>
            
        </el-table-column>
        <el-table-column prop="address" label="合同状态" show-overflow-tooltip>
          <template scope="scope">{{ scope.row.contractTemplateType }}</template>
          
        </el-table-column>
      </el-table>
    </el-card>

    <el-form-item label="退回到" prop="radio" style='marginTop:20px' >
      <el-radio v-model="ruleForm.radio" label="0" :disabled='dialogSendData.isAdd'>二审不通过</el-radio>
      <el-radio v-model="ruleForm.radio" label="1" :disabled='dialogSendData.isAdd'>废弃合同</el-radio>
    </el-form-item>
    <el-card class="box-card" v-if='ruleForm.radio==0' >
      <el-form-item label="风控审核备注" :prop="ruleForm.radio==0?'remark':null" >
        <el-input v-model="ruleForm.remark" placeholder="必填。" :maxlength='100' :disabled='dialogSendData.isAdd'></el-input>
      </el-form-item>
    </el-card>
    <el-form-item class='align'>
      <el-button type="primary"  @click="resetForm('ruleForm')" >返回</el-button>
      <el-button  type="success" @click="submitForm('ruleForm')" v-if='!dialogSendData.isAdd'>提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
  import qiniu from '@/views/qiniu/upload';
  import agentHttp from '@/utils/agentHttp.js'
  import {require,prop,decimalTwo} from '@/utils/rules.js'   //表单验证规则
  export default {
    data() {
      return {
        ruleForm: {
          contract:[],
          radio:'',
          remark:'',
        },
        rules: {
            contract: [require("合同")],
            radio: [require("选择状态")],
            remark : [require("审核备注")],
        },
        tableData:{},
      };
      
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate(valid => {
          if (valid) {
                      const params = {
                        comment:this.ruleForm.remark,
                        fromStatus:this.ruleForm.radio,
                        orderId:this.id,
                        contractTemplateInfoList:this.ruleForm.contract
                      }

                      if(params.contractTemplateInfoList.length==0){
                        this.$message.warning(`请至少选择一个合同模板`)
                      }else{
                      agentHttp.post(`adminApi/admin/mortgage_contractinfo/invalid_contract`,params).then(res=>{
                          this.dialogSendData.dialogFormVisible = false;
                          this.$message.success(res.data||"修改成功");
                          this.$emit('Refresh',null);
                      })
                      
                      }
          } 


        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.dialogSendData.dialogFormVisible = false;
      },
      select_default(rows){     //默认选择第一个合同
      if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
      is_select(){      //合同状态是否可以被勾选
    
      },
      initData(){
         agentHttp.get(`adminApi/admin/mortgage_contractinfo/get_contract_info/${this.id}`).then(res=>{
            if(res.success){
                  this.tableData = res.data
            }
         })
      },
      getTableId(arr){
          this.ruleForm.contract  = arr.map((items,index)=>{
                return items.id
             })
          console.dir(this.ruleForm.contract)
      }
    },
    props: {
      dialogSendData: {
        type: Object
      },
      id:{
        Number
      }
    },
    mounted() {
      this.initData()
     console.dir('id---'+this.id)
    },
    components: {
      qiniu
    }
  };

</script>

<style lang="scss" scoped>
  .text {
    font-size: 14px;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both;
  }

  .box-card {
    margin-top: 20px;
  }

  .align {
    margin: 50px auto 0;
    text-align: center;
  }

</style>

